#!/usr/bin/env python 3.9
# -*- coding = utr-8 -*-
'''
@Project: DouBan
@File: testUrllib_POST.py
@IDE: PyCharm
@Author: Simon
@Date: 5/3/21  12:47 AM
'''

from urllib.request import urlopen, Request
# 对于post进行解析
import urllib.parse


# Original post Requirement

# Using http://httpbin.org/ to Test
url = 'http://httpbin.org/post'
headers = {'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.85 Safari/537.36'}
# 封装数据
data = bytes(urllib.parse.urlencode({"hello":"world"}), encoding="utf-8")
retp = Request(url, headers=headers)
resp = urlopen(retp, data=data)
aa = resp.read().decode("utf-8")
print(aa)